package com.kaifamiao.www.ioDemo.do0921;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class FileInputStreamDemo {
    public static void main(String[] args) throws IOException {
        /**
         * read 读取单个字节 ，如果到达流的末尾，返回-1
         * skip 跳过指定的字节数，返回值表示实际跳过的字节数
         * available 获取流中剩余字节数
         */
        File file = new File("E:\\kaifamiao\\workspace\\idea--space\\io\\file-input.txt");
        if (file.exists()&&file.isFile()){
            //创建输出流对象
            FileInputStream fileInputStream = new FileInputStream(file);
            System.out.println("共有"+ file.length()+"个字节没读");
            int i = fileInputStream.read();
            System.out.println("读取到的字节是"+(char)i);
            System.out.println("还剩"+ fileInputStream.available()+ "个字节没读");
            //刚刚读过一个，所以减少一个
            fileInputStream.skip(3L);//跳过三个字节
            System.out.println("跳过3个字节，还剩"+fileInputStream.available()+"个字节没读");
            i=fileInputStream.read();
            System.out.println("读取到的字节是"+(char)i);

            //关闭流
            fileInputStream.close();
        }
    }
}
